package com.zrrd.gmall.mq.recevier;

import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@ComponentScan
@Configuration
public class ConfirmReceiver {

    //监听消息测试
    @SneakyThrows
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "queue.confirm",autoDelete = "false"),
            exchange = @Exchange(value = "exchange.confirm",autoDelete = "false"),
            key = {"routing.confirm"}))
    public void process(Message message, Channel channel) throws IOException {
        //打印获取到的信息
        System.out.println("收到了消息===>" + new String(message.getBody()));
        //消息发送确认回执
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
